<style lang="scss" scoped>
.coupons {
  margin-top: 3.5rem;
  background-color: #fff;
  border-radius: 8px;
  padding: 1.5rem 1rem 1rem;
  box-sizing: border-box;
  position: relative;

  .title {
    width: 12rem;
    height: 3rem;
    background: var(--btn_color);
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    line-height: 3rem;
    text-align: center;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -50%);
    letter-spacing: 0.3rem;
    font-size: 1.4rem;
    span {
      display: inline-block;
      width: 1rem;
      height: 1rem;
      border-radius: 1rem;
      background-color: #ffdb89;
    }
    span:nth-child(1) {
      margin-right: 0.5rem;
    }
    span:nth-child(2) {
      margin-left: 0.2rem;
    }
    .triangle_left_border {
      width: 0;
      height: 0;
      border-bottom: 1.5rem solid var(--btn_color);
      border-left: 1.5rem solid transparent;
      position: absolute;
      left: 0%;
      top: 0%;
      margin-left: -1.5rem;
    }
    .triangle_right_border {
      width: 0;
      height: 0;
      border-bottom: 1.5rem solid var(--btn_color);
      border-right: 1.5rem solid transparent;
      position: absolute;
      left: 100%;
      top: 0%;
    }
  }

  // 奖品
  .commission {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2.5rem;
    .conter_group_one {
      display: flex;
      align-items: center;
      .max {
        display: flex;
        align-items: center;
        margin-left: 1.2rem;
        font-size: 1.4rem;
        span {
          // padding: 100px;
          display: inline-block;
          margin-left: 10px;
        }
      }
    }
    .conter_group_two {
      display: flex;
      flex-direction: column;
      // text-align: right;
      font-size: 1.4rem;
      color: #999;
      span {
        // padding-bottom: 5px;
      }
      div {
        text-align: right;
      }
    }
  }

  .seamless-warp {
    height: 28rem;
    overflow: hidden;
  }

  .lottery-alert {
    max-width: 40rem;
    text-align: center;
    z-index: 10000;
    border-radius: 1rem;
    background: #fff;
    padding: 2rem;
    position: fixed;
    left: 0;
    right: 0;
    margin: auto 2rem;
    top: 50%;
    transform: translateY(-50%);
    .close-icon {
      position: fixed;
      width: 2.4rem;
      height: 2.4rem;
      right: 0.7rem;
      top: 0.7rem;
      border-radius: 1.2rem;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 3002;
      background: var(--btn_color);
    }
  }

  .mask {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    position: fixed;
    overflow: hidden;
    z-index: 222;
    top: 0;
    left: 0;
  }

  .lottery-alert h1 {
    font-size: 1.8rem;
    font-weight: bold;
    color: #d92b2f;
  }

  .lottery-alert img {
    display: block;
    margin: 0 auto;
  }

  .lottery-alert h2 {
    font-weight: normal;
    color: #d92b2f;
    font-size: 1.5rem;
    padding-top: 1.5rem;
  }

  .lottery-alert p {
    color: #666;
    font-size: 1.6rem;
    padding-top: 0.5rem;
  }

  .lottery-alert .btnsave {
    border-radius: 0.3rem;
    box-shadow: none;
    height: 4rem;
    cursor: pointer;
    line-height: 4rem;
    color: #fff;
    margin-top: 1.2rem;
    background: var(--btn_color);
    font-size: 1.4rem;
  }
}
</style>
<template>
  <div class="coupons" :style="{ '--btn_color': btn_color }">
    <div class="title">
      <span></span>
      <div>奖品详情</div>
      <span></span>
      <div class="triangle_left_border"></div>
      <div class="triangle_right_border"></div>
    </div>

    <!-- <vue-seamless-scroll
      :data="prizes"
      :class-option="optionSetting"
      class="seamless-warp"
    > -->
    <div class="commission" v-for="(item, i) in prizes" :key="i">
      <div class="conter_group_one">
        <div style="font-size: 1.6rem">
          {{ i + 1 }}
        </div>
        <div class="max">
          <div style="width: 40px; height: 40px">
            <img
              style="width: 40px; height: 40px; border-radius: 20px"
              :src="item.picture"
            />
          </div>
          <span>{{ item.name }}({{ item.prize_name }}{{ item.nums }}个)</span>
        </div>
      </div>
      <div class="conter_group_two">
        <span style="color: #333333; padding-bottom: 5px"
          >{{ item.power_nums }}次(助力)</span
        >
         
        <div v-show="new_status == 2 && exchange_num == 1">
          <van-button :color="btn_color" size="mini" @click="prizeClick(item)"
            >立即兑换</van-button
          >
        </div>
      </div>
    </div>
    <!-- </vue-seamless-scroll> -->

    <!-- 中奖弹窗 -->
    <div class="mask" v-if="showToast"></div>
    <div class="lottery-alert" v-if="showToast">
      <span
        class="close-icon"
        :style="{ backgroundColor: btn_color }"
        @click="btnClick"
        ><van-icon color="white" name="cross"
      /></span>
      <h1>恭喜您</h1>
      <p><img :src="single_prize.picture" alt="" /></p>
      <div></div>
      <template>
        <h2>获得{{ single_prize.name }}</h2>
        <h2>(活动中奖品只可以领奖一次)</h2>
        <div
          class="btnsave"
          v-if="single_prize.prize_type == 1"
          @click="sinceClick(single_prize)"
        >
          <!-- 请联系商家,核销奖品 -->
          点击领取奖品
        </div>
        <div class="btnsave" v-else @click="adressClick(single_prize)">
          <!-- 请填写收货地址,以便商家发送奖品 -->
          点击领取奖品
        </div>
      </template>
    </div>
  </div>
</template> 
<script>
import { Tab, Tabs, List, Loading, Button, Toast, Dialog, Icon } from "vant";
import NodataPiz from "@/components/NodataPiz";
// import CaseList from "@/components/CaseList.vue";
export default {
  name: "PrizeDetail",
  components: {
    [List.name]: List,
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [Loading.name]: Loading,
    [Button.name]: Button,
    [Icon.name]: Icon,
    [Toast.name]: Toast,
    [Dialog.name]: Dialog,
    NodataPiz,
  },
  props: {
    activityItem: {
      type: Object,
      required: true,
    },
    prizes: {
      type: Array,
      required: true,
    },
    oneself_num: {
      type: Number,
      require: true,
    },
    openid: {
      type: String,
      require: true,
    },
    prize_status: {
      type: Number,
      require: true,
    },
    order_num: {
      type: Number,
      require: true,
    }
  },
  watch: {},
  data() {
    return {
      btn_color: "",
      comList: [],
      num: null,
      showToast: false,
      new_status: null,
      single_prize: {},
      exchange_num: null,
      order_id: null
    };
  },
  // computed: {
  //   optionSetting() {
  //     return {
  //       step: 0.4, // 数值越大速度滚动越快
  //       limitMoveNum: 2, // 开始无缝滚动的数据量 this.dataList.length
  //       hoverStop: true, // 是否开启鼠标悬停stop
  //       direction: 1, // 0向下 1向上 2向左 3向右
  //       openWatch: true, // 开启数据实时监控刷新dom
  //       singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
  //       singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
  //       waitTime: 1000, // 单步运动停止的时间(默认值1000ms)
  //     };
  //   },
  // },
  watch: {
    oneself_num: {
      handler(val) {
        this.num = val;
      },
    },
    prize_status: {
      handler(val) {
        this.new_status = val;
      },
    },
    order_num: {
      handler(val) {
        console.log(val, '----------------------------');
        this.exchange_num = val
      }
    }
  },
  created() {
    const _this = this;
    _this.btn_color = _this.activityItem.btn_color;
    console.log(_this.activityItem, "commissionList");
    this.bus.$on("getNum", (val) => {
      this.num = val;
      this.numclick();
    });
  },
  mounted() {},
  destroyed(){
    console.log('destroy')
    this.bus.$off("getNum")
  },
  methods: {
    prizeClick(item) {
      this.single_prize = item;
      console.log("this.single_prize",this.single_prize)
      console.log("this.num", this.num);
      this.$emit("prizeDates");
    },
    numclick() {
      if (!this.num) {
        this.num = 0;
      }
      // alert('this.single_prize.power_nums'+this.single_prize.power_nums)
      // alert('this.num'+this.num)
      let powerNum = this.single_prize.power_nums
      // alert('powerNum'+powerNum)
      if(powerNum=='undefined'){
        
      }else{
        if (powerNum > this.num) {
        this.$toast(
          `您的助力次数为${this.num}次\n未达到兑换次数,请去邀请好友来助力`
        );
      }else if(this.single_prize.nums == 0){
         this.$toast(
          `该奖品已兑换完毕,请去兑换其他奖品`
        );
      }else {
        Dialog.confirm({
          title: "系统提示",
          message: "您的助力次数已达到,确认要去兑换奖品吗？",
        }).then(() => {
          this.showToast = true;
        }).catch(() => {
          // on cancel
        });
      }
      }
      
    },
    // 关闭按钮
    btnClick() {
      this.showToast = false;
    },
    // 自提奖品
    sinceClick(item) {
      let params = {
        activity_id: item.activity_id,
        openid: this.openid,
        prize_id: item.prize_id,
      };
      console.log(item);
      this.$request.getDoDraws(params).then((res) => {
        console.log(res);
        this.new_status = 1
        this.showToast = false;
        this.$toast("领取成功,请联系商家,核销奖品");
      });
    },
    // 跳到填写地址
    adressClick(item) {
      let params = {
        activity_id: item.activity_id,
        openid: this.openid,
        prize_id: item.prize_id,
      };
      console.log(params, item);
      this.$store.commit("setThemeColor", this.activityItem.theme_color);
      this.$store.commit("setprizeItem", this.single_prize.name);
      this.$request.getDoDraws(params).then((res) => {
        console.log(res);
        this.showToast = false;
        this.order_id = res.data.order_id;
        this.$router.push(
          `/caseShow/envelopesTalk/AdressForm?order_id=${this.order_id}&activity_id=${this.activityItem.id}&oid=4`
        );
      });
    },
  },
};
</script>
